<?php
namespace app\api\controller;

use app\api\model\CourseModel;
use think\Controller;

class Course extends  Controller
{
    function courselist() {
        $model = new CourseModel();
        $result = $model->courselist();
        return json_encode($result);
    }
    function coursedetail() {
        $courseid = input('get.courseid');
        $model = new CourseModel();
        $result = $model->coursedetail($courseid);
        if ($result) {
            return json_encode($result);
        }else {
            return  json_encode(['id'=>0]);
        }


    }

    function courseenroll() {
        $sessionid = input('get.sessionid');
        $userid = input('get.userid');
        $courseid = input('get.courseid');

        session_start();
        $redis = getRedis();
        if ($sessionid!='' && $sessionid == $redis->get($userid)) {
            $model = new CourseModel();
            $result = $model->courseenroll($userid,$courseid);
            return json_encode($result);
        }
        return  json_encode(['error'=>'sessionid无效']);
    }

}